﻿<Window x:Class="Profit.Views.FittingsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ComponentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase" 
        xmlns:Resources="clr-namespace:Profit.Resources" 
        mc:Ignorable="d"
        d:DesignHeight="291" 
        d:DesignWidth="431"
        Width="430"
        Height="290"
        ShowInTaskbar="False"
        SizeToContent="Manual"
        ResizeMode="CanResize"
        Title="{x:Static Resources:Messages.label_fittings_list}"
        Icon="/Profit;component/Resources/Icons/app_32.ico" >
    
    <Window.Resources>
        <CollectionViewSource x:Key="fittingsSource" Source="{Binding Fittings, Mode=OneWay}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Robot.Faction"/>
            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions >
                <ComponentModel:SortDescription PropertyName="Name" Direction="Ascending"  />
                <ComponentModel:SortDescription PropertyName="Robot.Name" Direction="Ascending"  />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="1*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ListView x:Name="fittingsList" Grid.Row="0" ItemsSource="{Binding Source={StaticResource fittingsSource}, Mode=OneWay}" SelectedItem="{Binding SelectedFitting, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True">
            <ListView.View>
                <GridView AllowsColumnReorder="False" >
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name, Mode=OneWay}" />
                    <GridViewColumn Header="Robot" DisplayMemberBinding="{Binding Robot.Name, Mode=OneWay}" />
                    <GridViewColumn Header="Size" DisplayMemberBinding="{Binding Robot.Size, Mode=OneWay}" />
                </GridView>
            </ListView.View>
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{x:Static Resources:Messages.menu_delete_fitting}" Command="{Binding DeleteFittingCommand}" CommandParameter="{Binding SelectedFitting}" />
                </ContextMenu>
            </ListView.ContextMenu>
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle >
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Border>
                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
                                                <Border Grid.Row="0" BorderBrush="{StaticResource HorizontalNormalBrush}" CornerRadius="0" BorderThickness="0,0,0,2" Margin="4,2">
                                                    <TextBlock Margin="5,0,0,0" FontWeight="Bold" >
                                                            <TextBlock.Text>
                                                                <MultiBinding StringFormat="{}{0} ({1})">
                                                                    <Binding Path="Name" Mode="OneTime" />
                                                                    <Binding Path="ItemCount" Mode="OneTime" />
                                                                </MultiBinding>
                                                            </TextBlock.Text>
                                                    </TextBlock>
                                                </Border>
                                                <ItemsPresenter Grid.Row="1" />
                                            </Grid>
                                        </Border>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </ListView.GroupStyle>
        </ListView>
    </Grid>
</Window>
